package com.bite.xml_basic_write;

import org.dom4j.Document;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;

import java.io.FileOutputStream;
import java.io.OutputStream;

/**
 * 写出文件的细节
 */
public class Demo2 {
    public static void main(String[] args) throws Exception{

        //读取xml文件
        Document doc = new SAXReader().read(Demo1.class.getClassLoader().getResource("contact.xml"));


        //创建输出流对象:指定当前硬盘路径
        OutputStream out = new FileOutputStream("e:/contact.xml") ;
        //创建输出格式:OutputFormat
       // OutputFormat format = OutputFormat.createCompactFormat() ;//紧凑格式  :上线用
        OutputFormat format = OutputFormat.createPrettyPrint();//优雅格式 :测试时用
       //设置的编码格式
        format.setEncoding("utf-8");
        XMLWriter writer = new XMLWriter(out,format) ;
        writer.write(doc);
        //关闭
        out.close();

    }
}
